package com.sandking.db.bean;

import com.sandking.tools.SK_Map;
import java.util.ArrayList;
import java.util.Map;
import java.util.List;
import com.sandking.db.cache.YxjnCache;
import com.sandking.db.cache.YhyxCache;
import java.util.HashMap;

/**
 * 英雄技能
 */
public class Yxjn {
	/**
	 * 需要更新字段集
	 */
	private Map<String, Object> updateColumns;

	/** id */
	private int id;
	
	/** 用户英雄_id */
	private int yhyx_id;
	
	/** 技能id */
	private int jnid;
	
	/** 技能lvl */
	private int jnlvl;
	
	
	public Yxjn() {
		super();
	}
	
	public Yxjn(int id, int yhyx_id, int jnid, int jnlvl) {
		super();
		this.id = id;
		this.yhyx_id = yhyx_id;
		this.jnid = jnid;
		this.jnlvl = jnlvl;
	}
	
	public Map<String, Object> getUpdateColumns() {
		if(updateColumns == null)
			updateColumns = new HashMap<String, Object>();
		return updateColumns;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
		addUpdateColumn("id",id);
	}
	
	public void changeIdWith(int id){
		this.id += id;
		setId(this.id);
	}
	
	public void changeIdWithMin(int id,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMax(int id,int max){
		this.id += id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMaxMin(int id,int max,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}	
	public int getYhyx_id() {
		return yhyx_id;
	}
	
	public void setYhyx_id(int yhyx_id) {
		this.yhyx_id = yhyx_id;
		addUpdateColumn("用户英雄_id",yhyx_id);
	}
	
	public void changeYhyx_idWith(int yhyx_id){
		this.yhyx_id += yhyx_id;
		setYhyx_id(this.yhyx_id);
	}
	
	public void changeYhyx_idWithMin(int yhyx_id,int min){
		this.yhyx_id += yhyx_id;
		this.yhyx_id = this.yhyx_id < min ? min : this.yhyx_id;
		setYhyx_id(this.yhyx_id);
	}
	
	public void changeYhyx_idWithMax(int yhyx_id,int max){
		this.yhyx_id += yhyx_id;
		this.yhyx_id = this.yhyx_id > max ? max : this.yhyx_id;
		setYhyx_id(this.yhyx_id);
	}
	
	public void changeYhyx_idWithMaxMin(int yhyx_id,int max,int min){
		this.yhyx_id += yhyx_id;
		this.yhyx_id = this.yhyx_id < min ? min : this.yhyx_id;
		this.yhyx_id = this.yhyx_id > max ? max : this.yhyx_id;
		setYhyx_id(this.yhyx_id);
	}	
	public int getJnid() {
		return jnid;
	}
	
	public void setJnid(int jnid) {
		this.jnid = jnid;
		addUpdateColumn("技能id",jnid);
	}
	
	public void changeJnidWith(int jnid){
		this.jnid += jnid;
		setJnid(this.jnid);
	}
	
	public void changeJnidWithMin(int jnid,int min){
		this.jnid += jnid;
		this.jnid = this.jnid < min ? min : this.jnid;
		setJnid(this.jnid);
	}
	
	public void changeJnidWithMax(int jnid,int max){
		this.jnid += jnid;
		this.jnid = this.jnid > max ? max : this.jnid;
		setJnid(this.jnid);
	}
	
	public void changeJnidWithMaxMin(int jnid,int max,int min){
		this.jnid += jnid;
		this.jnid = this.jnid < min ? min : this.jnid;
		this.jnid = this.jnid > max ? max : this.jnid;
		setJnid(this.jnid);
	}	
	public int getJnlvl() {
		return jnlvl;
	}
	
	public void setJnlvl(int jnlvl) {
		this.jnlvl = jnlvl;
		addUpdateColumn("技能lvl",jnlvl);
	}
	
	public void changeJnlvlWith(int jnlvl){
		this.jnlvl += jnlvl;
		setJnlvl(this.jnlvl);
	}
	
	public void changeJnlvlWithMin(int jnlvl,int min){
		this.jnlvl += jnlvl;
		this.jnlvl = this.jnlvl < min ? min : this.jnlvl;
		setJnlvl(this.jnlvl);
	}
	
	public void changeJnlvlWithMax(int jnlvl,int max){
		this.jnlvl += jnlvl;
		this.jnlvl = this.jnlvl > max ? max : this.jnlvl;
		setJnlvl(this.jnlvl);
	}
	
	public void changeJnlvlWithMaxMin(int jnlvl,int max,int min){
		this.jnlvl += jnlvl;
		this.jnlvl = this.jnlvl < min ? min : this.jnlvl;
		this.jnlvl = this.jnlvl > max ? max : this.jnlvl;
		setJnlvl(this.jnlvl);
	}	
	
	//用户英雄_id
	public Yhyx getYhyxPkYhyx_id(){
		return YhyxCache.getById(yhyx_id);
	}
	public void addUpdateColumn(String key, Object val) {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.put(key, val);
	}
	
	public void clearUpdateColumn() {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.clear();
	}
	
	public Map<String, Object> toMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", id);
        result.put("yhyx_id", yhyx_id);
        result.put("jnid", jnid);
        result.put("jnlvl", jnlvl);
        return result;
    }
    
    public String toString(){
        return toMap().toString();
    }
    
    /**
     * 根据list创建对象
     */
    public static List<Yxjn> createForList(List<Map<String, Object>> list){
    	List<Yxjn> yxjns = new ArrayList<Yxjn>();
		for (Map<String, Object> map : list) {
			yxjns.add(createForMap(map));
		}
		return yxjns;
    }
    
    /**
     * 根据map创建对象
     */
    public static Yxjn createForMap(Map<String, Object> map){
    	Yxjn obj = new Yxjn();
	    obj.id = SK_Map.getInt("id", map);
	    obj.yhyx_id = SK_Map.getInt("用户英雄_id", map);
	    obj.jnid = SK_Map.getInt("技能id", map);
	    obj.jnlvl = SK_Map.getInt("技能lvl", map);
        return obj;
    }
    /** 延迟插入数据库 */
    public Yxjn insert(){
    	return YxjnCache.insert(this);
    }
    /** 延迟更新数据库 */
    public Yxjn update(){
    	return YxjnCache.update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return YxjnCache.delete(this);
    }
    /** 即时插入数据库 */
    public Yxjn insertAndFlush(){
    	return YxjnCache.insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Yxjn updateAndFlush(){
    	return YxjnCache.updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return YxjnCache.deleteAndFlush(this);
    }
}